package cn.tedu.myweb.service.impl;

import cn.tedu.myweb.exception.ServiceException;
import cn.tedu.myweb.mapper.NotifyMapper;
import cn.tedu.myweb.model.Notify;
import cn.tedu.myweb.service.INotifyService;
import cn.tedu.myweb.vo.NotifyVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NotifyServiceImpl extends ServiceImpl<NotifyMapper,Notify> implements INotifyService {
    @Autowired
    NotifyMapper notifyMapper;

    @Override
    public List<Notify> getNotifies(String username) {
        List<Notify> notifies = notifyMapper.getNotifies(username);
        return notifies;
    }

    @Override
    public void saveNotify(NotifyVo notifyVo,String userName) {
        Notify notify = new Notify()
                .setFriendName(userName)
                .setUserName(notifyVo.getUserName())
                .setMessage(notifyVo.getMessage())
                .setTypeId(notifyVo.getTypeId());

        int num = notifyMapper.insert(notify);
        if(num!=1){
            throw new ServiceException("数据库忙！");
        }
    }
}
